package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OjProblems;
import com.ruoyi.system.service.IOjProblemsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * OJ题目Controller
 * 
 * @author ruoyi
 * @date 2025-08-29
 */
@RestController
@RequestMapping("/system/oj_problems")
public class OjProblemsController extends BaseController
{
    @Autowired
    private IOjProblemsService ojProblemsService;

    /**
     * 查询OJ题目列表
     */
    @PreAuthorize("@ss.hasPermi('system:oj_problems:list')")
    @GetMapping("/list")
    public TableDataInfo list(OjProblems ojProblems)
    {
        startPage();
        List<OjProblems> list = ojProblemsService.selectOjProblemsList(ojProblems);
        return getDataTable(list);
    }

    /**
     * 导出OJ题目列表
     */
    @PreAuthorize("@ss.hasPermi('system:oj_problems:export')")
    @Log(title = "OJ题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OjProblems ojProblems)
    {
        List<OjProblems> list = ojProblemsService.selectOjProblemsList(ojProblems);
        ExcelUtil<OjProblems> util = new ExcelUtil<OjProblems>(OjProblems.class);
        util.exportExcel(response, list, "OJ题目数据");
    }

    /**
     * 获取OJ题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:oj_problems:query')")
    @GetMapping(value = "/{ojProblemId}")
    public AjaxResult getInfo(@PathVariable("ojProblemId") Long ojProblemId)
    {
        return success(ojProblemsService.selectOjProblemsByOjProblemId(ojProblemId));
    }

    /**
     * 新增OJ题目
     */
    @PreAuthorize("@ss.hasPermi('system:oj_problems:add')")
    @Log(title = "OJ题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OjProblems ojProblems)
    {
        return toAjax(ojProblemsService.insertOjProblems(ojProblems));
    }

    /**
     * 修改OJ题目
     */
    @PreAuthorize("@ss.hasPermi('system:oj_problems:edit')")
    @Log(title = "OJ题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OjProblems ojProblems)
    {
        return toAjax(ojProblemsService.updateOjProblems(ojProblems));
    }

    /**
     * 删除OJ题目
     */
    @PreAuthorize("@ss.hasPermi('system:oj_problems:remove')")
    @Log(title = "OJ题目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ojProblemIds}")
    public AjaxResult remove(@PathVariable Long[] ojProblemIds)
    {
        return toAjax(ojProblemsService.deleteOjProblemsByOjProblemIds(ojProblemIds));
    }
}
